/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Preferences.java
 *
 * Created on Aug 25, 2010, 10:06:08 AM
 */

package buggymastercode;

import org.jdesktop.application.Action;

/**
 *
 * @author jalvarez
 */
public class PreferencesDialog extends javax.swing.JDialog {

    /** Creates new form Preferences */
    public PreferencesDialog(java.awt.Frame parent) {
        super(parent, true);
        initComponents();
    }

    public boolean initDialog () {
        Preference pref = PreferenceObject.getPreference(G.C_AUX_FUN_ID);
        if (pref != null) {
            if (pref.getValue().equals(G.C_AUX_FUN_IN_CLASS_SOURCE)) {
                opInClassSource.setSelected(true);
            }
            else if (pref.getValue().equals(G.C_AUX_FUN_IN_G_CLASS)) {
                opInGClass.setSelected(true);
            }
            else if (pref.getValue().equals(G.C_AUX_FUN_IN_CS_LIBRARY)) {
                opInCSUtils.setSelected(true);
            }
        }
        else {
            // default is to add auxiliary functions to the class source
            //
            opInClassSource.setSelected(true);
        }
        pref = PreferenceObject.getPreference(G.C_AUX_ADO_REPLACE_ID);
        if (pref != null) {
            if (!pref.getValue().equals("0")) {
                chkReplaceADO.setSelected(true);
            }
            else {
                chkReplaceADO.setSelected(false);
            }
        }
        else {
            chkReplaceADO.setSelected(false);
        }
        return true;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        opGroupAuxiliaryFunctions = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        opInClassSource = new javax.swing.JRadioButton();
        opInGClass = new javax.swing.JRadioButton();
        opInCSUtils = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        chkReplaceADO = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(buggymastercode.BuggyMasterCodeApp.class).getContext().getResourceMap(PreferencesDialog.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setMinimumSize(new java.awt.Dimension(542, 320));
        setName("Form"); // NOI18N
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel1.border.title"))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        opGroupAuxiliaryFunctions.add(opInClassSource);
        opInClassSource.setText(resourceMap.getString("opInClassSource.text")); // NOI18N
        opInClassSource.setName("opInClassSource"); // NOI18N

        opGroupAuxiliaryFunctions.add(opInGClass);
        opInGClass.setText(resourceMap.getString("opInGClass.text")); // NOI18N
        opInGClass.setName("opInGClass"); // NOI18N

        opGroupAuxiliaryFunctions.add(opInCSUtils);
        opInCSUtils.setText(resourceMap.getString("opInCSUtils.text")); // NOI18N
        opInCSUtils.setName("opInCSUtils"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 449, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(opInClassSource)
                    .addComponent(opInGClass)
                    .addComponent(opInCSUtils))
                .addContainerGap(31, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(opInClassSource)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(opInGClass)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(opInCSUtils)
                .addContainerGap())
        );

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(buggymastercode.BuggyMasterCodeApp.class).getContext().getActionMap(PreferencesDialog.class, this);
        jButton1.setAction(actionMap.get("save")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel2.border.title"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        chkReplaceADO.setText(resourceMap.getString("chkReplaceADO.text")); // NOI18N
        chkReplaceADO.setName("chkReplaceADO"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(chkReplaceADO)
                .addContainerGap(165, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(chkReplaceADO)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void save() {
        Preference pref = new Preference();
        pref.setId(G.C_AUX_FUN_ID);
        if (opInClassSource.isSelected()) {
            pref.setValue(G.C_AUX_FUN_IN_CLASS_SOURCE);
        }
        else if (opInGClass.isSelected()) {
            pref.setValue(G.C_AUX_FUN_IN_G_CLASS);
        }
        else if (opInCSUtils.isSelected()) {
            pref.setValue(G.C_AUX_FUN_IN_CS_LIBRARY);
        }
        PreferenceObject.savePreference(pref);
        pref.setId(G.C_AUX_ADO_REPLACE_ID);
        if (chkReplaceADO.isSelected()) {
            pref.setValue("-1");
        }
        else {
            pref.setValue("0");
        }
        PreferenceObject.savePreference(pref);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox chkReplaceADO;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.ButtonGroup opGroupAuxiliaryFunctions;
    private javax.swing.JRadioButton opInCSUtils;
    private javax.swing.JRadioButton opInClassSource;
    private javax.swing.JRadioButton opInGClass;
    // End of variables declaration//GEN-END:variables

}
